package com.jeff.practice;

//n个硬币最多摆多少行 第k行必须有k个硬币
public class Test7 {
    public static void main(String[] args) {
        System.out.println(getMaxRow(100));
    }

    public static int getMaxRow(int n) {
        int max = 0;
        int sum;
        for (int i = 1; i <= n; i++) {
            //假设有i行,求i行硬币总数
            sum = (1 + i) * i / 2;
            if (sum <= n) {
                max = i;
            }
            else {
                break;
            }
        }
        return max;
    }
}
